package com.zsh.servlet;

import com.google.gson.Gson;
import com.zsh.pojo.Person;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.Period;

public class AjaxServlet extends BaseServlet {

    protected void jsAjax(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ajax请求过来了");

        Person person = new Person(1,"张生华");

        Gson gson = new Gson();
        String jsonStr = gson.toJson(person);

        resp.getWriter().write(jsonStr);


    }

    protected void jQueryAjax(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryAjax请求过来了");

        Person person = new Person(1,"张生华");

        Gson gson = new Gson();
        String jsonStr = gson.toJson(person);

        resp.getWriter().write(jsonStr);
    }

    protected void jQueryGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryGet请求过来了");

        Person person = new Person(1,"张生华");

        Gson gson = new Gson();
        String jsonStr = gson.toJson(person);

        resp.getWriter().write(jsonStr);
    }

    protected void jQueryPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryPost请求过来了");

        Person person = new Person(1,"张生华");

        Gson gson = new Gson();
        String jsonStr = gson.toJson(person);

        resp.getWriter().write(jsonStr);
    }

    protected void jQueryGetJson(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryGetJson请求过来了");

        Person person = new Person(1,"张生华");

        Gson gson = new Gson();
        String jsonStr = gson.toJson(person);

        resp.getWriter().write(jsonStr);
    }

    protected void jQuerySerialize(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("jQueryGetJson请求过来了");

        Person person = new Person(1,"张生华");

        Gson gson = new Gson();
        String jsonStr = gson.toJson(person);

        resp.getWriter().write(jsonStr);
    }
}
